package com.test.thrift;

import com.test.thrift.service.QueryProxyService;
import com.test.thrift.service.impl.QueryProxyServiceImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportException;
import org.apache.thrift.server.TThreadPoolServer.Args;

/**
 * Created by MAC on 2018/10/23.
 */
public class Main {
    private static final Log log = LogFactory.getLog(Main.class);
    public static void main(String[] args) throws TTransportException {
        Main main = new Main();
        main.startUp();
    }

    public void startUp() throws TTransportException {

        TServerSocket serverTransport = new TServerSocket(9090);
        QueryProxyServiceImpl service = new QueryProxyServiceImpl();


        TProcessor processor = new QueryProxyService.Processor<QueryProxyService.Iface>(service);
        TBinaryProtocol.Factory factory = new TBinaryProtocol.Factory(true, true);
        Args tArgs = new Args(serverTransport);
        tArgs
                .minWorkerThreads(1)
                .maxWorkerThreads(20)
                .processor(processor)
                .protocolFactory(factory);
        TServer server = new TThreadPoolServer(tArgs);
        System.out.println("Starting the server...");
        server.serve();
        log.info("server ");
    }
}
